package com.tedu.lianxi1.controller;

import com.tedu.lianxi1.mapper.WeiboMapper;
import com.tedu.lianxi1.pojo.dto.WeiboDTO;
import com.tedu.lianxi1.pojo.entity.Weibo;
import com.tedu.lianxi1.pojo.vo.WeiboVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
@RequestMapping("/v1/weibo")
public class WeiboController {
    @Autowired
    private WeiboMapper weiboMapper;
    @Autowired
    private HttpSession httpSession;

    @PostMapping("/insert")
    @ResponseBody
    public int insert(@RequestBody WeiboDTO weiboDTO){
        Weibo weibo=new Weibo();
        BeanUtils.copyProperties(weiboDTO,weibo);
        weibo.setCreated(new Date());
       if (weiboMapper.selectByuserId(weibo.getUserId())!=null){
           int num = weiboMapper.insert(weibo);
           System.out.println("插入微博记录行数："+num);
           return 1;
       }else {
           return 2;
       }




    }
}
